#include "../../../source/sgl.h"
#include "../../common/background.h"

static sgl_img_t bg_img = {.bitmap = bg_test, .width = 240, .height = 320,};
static void sw_event(sgl_obj_t *obj, void *data)
{
    if(sgl_ev_stat(obj) == SGL_EVENT_PRESSED) {
        SGL_LOG_INFO("sw pressed");
    }
    else if(sgl_ev_stat(obj) == SGL_EVENT_RELEASED) {

    };
}


sgl_style_t sw_style = {.body_color = sgl_rgb(10,200,20), .radius = 17};
sgl_obj_t* sw;
sgl_obj_t *main_page;

void demo_setup(void)
{
    SGL_LOG_INFO("switch demo");
    main_page = sgl_page_create();

    sgl_page_set_background(main_page, &bg_img);

    sgl_page_set_active(main_page);

    //创建一个开关对象，默认是开启状态
    sw = sgl_switch_create(main_page, true);
    //设置开关的大小为宽124和高34
    sgl_obj_set_size(sw, 80, 34);
    //设置开关的位置为中心向左对齐
    sgl_obj_set_align(sw, SGL_ALIGN_CENTER_LEFT);
    //设置开关的样式
    sgl_obj_set_style(sw, &sw_style);
    //设置开关的点击事件
    sgl_obj_set_event_cb(sw, sw_event, NULL);
    //设置开关的关闭状态下的颜色
    sgl_switch_set_toggle_color(sw, sgl_rgb(50,50,50));
    //设置开关的初始状态
    sgl_switch_set_status(sw, false);
    //sgl_switch_set_anim(sw, true);
}
